<template>
  <div class="app-container">
    <el-form :inline="true" :model="formInline" ref="formInline" class="demo-form-inline">
      <el-form-item label="交易时间" prop="time">
        <el-date-picker
          v-model="formInline.time"
          type="datetimerange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
          value-format="yyyy-MM-dd HH:mm:ss"
          >
        </el-date-picker>
      </el-form-item>
      <el-form-item class="with-pre-select" label="会员帐户名" prop="userName">
        <el-input placeholder="请输入会员帐户名" v-model="formInline.userName" class="input-with-select" @keyup.enter.native="handleFilter"></el-input>
      </el-form-item>
      <el-form-item label="交易类型" prop="tradeType" style="width: 400px">
        <el-select
          v-model="formInline.tradeType" width="100%" placeholder="请选择交易类型">
          <el-option label="全部" :value="Number(0)"></el-option>
          <el-option
            v-for="item in consts.MEMBER_ORDER_TYPE"
             v-if="[1,2].indexOf(item.value)>-1"
            :label="item.title"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>     
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <el-button @click="cancel('formInline')">重置</el-button>
    </el-form>
  </div>

</template>

<script>
  import {form} from '@/build'

  export default {
    name: "form-filter",
    mixins: [form],
    data() {
      return {
        formInline: {
          tradeType:0,
          userName: undefined,
          time: [moment().startOf('month').format('YYYY-MM-DD 00:00:00'), moment().format('YYYY-MM-DD 23:59:59')],
        },
      }
    },
    methods: {
      handleFilter() {
        this.$emit('on-filter', this.formInline)
      },
      cancel(formName) {
        this.resetForm(formName)
        this.handleFilter()
      }
    }
  }
</script>

<style lang="scss" scoped>
  .with-pre-select {
    .el-input-group__prepend {
      .el-select {
        width: 80px;
      }
    }
  }

  .money-range {
    .el-input {
      width: 100px;
    }
  }

</style>
